<?php
/**
* Red RUgolok
* @version $Id: redrugolok.html.php
* @package RUgolok
* @subpackage redrugolok.html.php
* @author el_leo and manicon
* @copyright (C) el_leo and manicon, www.rugolok.de
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/


defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class HTML_redrugolok {

/**
 * Hauptseite.
 * Default Template fuer diese Komponente.
 *
 */
function redrugolok() {
?>

<?php mosLoadModules( 'fr_top' ); ?>

		<div style="float:left;width:35%;padding: 5px;" id="left_col">
			<?php mosLoadModules( 'fr_left1' ); ?>
		</div>
		<div style="float:left;width:30%;padding: 5px;" id="center"><?php mosLoadModules( 'fr_middle1' ); ?></div>
		<div style="float:left;width:25%;padding: 5px;" id="right_col"><?php mosLoadModules( 'fr_right1' ); ?></div>
		
		<?php mosLoadModules( 'fr_bottom' ); ?>
	<?php
}

/** 
 * listRatings
 */
function listRatings(){
	?>
		<div class="rr_box">
			<div class="rr_box_heading">Ratings</div>
			
		</div>
<?php
}



/**
 * Template fuer die Darstelleung der Liste mit neuen Items
 * @param Array Array oder Liste von Objekten
 */
function listNew($items) {
	?>
		<div class="rr_box">
			<div class="rr_box_heading">New</div>
	<?php
		foreach($items as $item) {
			if($item->is_text) {
				$temp = trim( $item->is_text );
			} else
				$temp = "";

		?>
			<div class="rr_newItem">
				<strong>Title></strong>
				<p><?=$temp?></p>

				<a href=""><div class="rr_newItem_more">weiter...</div></a>
			</div>
		</div>
		<?php
		}
}


/**
 * Zeige Typ
 */

function showType($type, $item_list_new = null, $item_list_top = null, $item_list = null) {
	global $Itemid, $mosConfig_live_site;
	if(!$item_list) {
		HTML_redrugolok::warning(_RR_CATEGORY_EMPTY);
	} else {
			foreach($item_list as $item) {
	
				if (strlen($item->text)>91) $teil = substr($item->text,0,91)."...";
				else $teil = $item->text;
			?>
				<div class="rr_item_small_box">
					<div class="rr_item_small_box_header">
						<?=$item->id?>
						<?=date(_RR_DATE_FORMAT, $item->date);?>
					</div>
					<div class="rr_item_small_container">
						<a href="index.php?option=com_redrugolok&Itemid=<?=$Itemid?>&task=show&item_id=<?=$item->id?>"><div class="rr_item_small_box_title"><?=$item->title;?></div></a>
						<div class="rr_item_small_box_body"><?=$teil;?></div>
					</div>
					<div class="rr_item_small_box_footer">
						<div style="width:47%;float:left"><img src="<?=$mosConfig_live_site?>/components/com_redrugolok/images/icon_points.png"> <?=$item->points?></div>
						<div style="width:47%;float:left"><img src="<?=$mosConfig_live_site?>/components/com_redrugolok/images/icon_nummarks.png"> <?=$item->num_marks?> </div>
						<div style="width:47%;float:left"><img src="<?=$mosConfig_live_site?>/components/com_redrugolok/images/icon_numcomments.png"> <?=/*$item->num_comments*/?> 0</div>
						<div style="width:47%;float:left"><img src="<?=$mosConfig_live_site?>/components/com_redrugolok/images/icon_numviews.png"> <?=$item->views?></div>
					</div>
				</div>
			<?php
			}
		}
	}

/**
 * Show the commenting system for this item 
 */
function showComments($item_id) {
?>

	<div class="rr_comments_heading"><?=_RR_COMMENTS_HEADER?></div>
	<div class="rr_comments_body" id="rr_comments_body">
	<div>
	<form action="index.php?option=com_redrugolok&Itemid=143&task=comment&item_id=5#comment" method="post" name="form" id="form">
		<textarea cols="80" rows="5" name="comment_text" id="comment_text"></textarea><br/>
		<input type="hidden" name="item_id" value="<?=$item_id?>">
		<input type="submit" name="submit" value="click" style="width:200px">
	</form>
	</div>
		<?php
		$comments = getCommentsByItemId($item_id);
		if($comments) {
		foreach($comments as $comment) {
		?>
		
		<div class="comment_body">
			<h1><?=_RR_COMMENT_AUTHOR?><a href=""><?=show_username($comment->jos_user_id, get_username($comment->jos_user_id))?></a></h1><small><?=date("d.m.y G:i", $comment->comment_date)?></small>
			<p><?=$comment->comment_text?></p>
		</div>
		
		<?php } }
				else {
					echo "<div class=\"comment_body\" style=\"align:center\">"._RR_NO_COMMENTS."</div>";
				}
		?>
	</div>
	
<?php
}

/**
 * Show the rating system for this item
 */
function showRatings($item) {
		global $my;
?>
	<div class="rr_ratings_heading"><?=_RR_RATINGS_HEADER?></div>
	<div class="rr_ratings_body">
		<p><?=$item->points?></p>
		<?php
		$may_rate = may_rate($item->id, $my->id);
		if ($may_rate == "ok")
		{
		?>
		<form action="index.php?Itemid=<?php echo mosGetParam( $_REQUEST, 'Itemid', 1 ); ?>&option=com_redrugolok&task=rate" method="post">
		<p>
			<table align="center" border="0">
			<tr>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=1 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=2 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=3 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=4 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=5 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=6 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=7 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=8 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=9 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=10 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=11 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=12 ></input></td>
				<td><INPUT TYPE="radio" NAME="mark" VALUE=13 ></input></td>
			</tr>
			<tr>
				<td align="center">1</td>
				<td align="center">2</td>
				<td align="center">3</td>
				<td align="center">4</td>
				<td align="center">5</td>
				<td align="center">6</td>
				<td align="center">7</td>
				<td align="center">8</td>
				<td align="center">9</td>
				<td align="center">10</td>
				<td align="center">11</td>
				<td align="center">12</td>
				<td align="center">13</td>
			</tr>
			</table>
	 	</p>
              <input type="hidden" name="action" value="rate">
              <input type="hidden" name="item_id" value="<?php echo $item->id; ?>">
              <?php if ($my->id == 0) {
              			echo "guestname"; ?><input type="text" size="8" value="Guest" name="guestname" id="guestname" ><br>
              			<input type="text" size="8" value="Hashcode" name="hash" id="hash" ><br><hr>
              <?php } ?>
              <input type="submit" value="Rate!">
	    </form>
	    <?php
		}
		else echo $may_rate;
		?>
	</div>
<?php
}


/**
 * Show the small information about this item
 */
function showSmall($item) {
	global $Itemid;
?><h3><?=$item->title;?></h3>
		<?=$item->text;?>
	<a href="index.php?option=com_redrugolok&Itemid=<?=$Itemid?>&task=show&item_id=<?=$item->id?>"><div class="rr_item_of_the_day_more">weiter...</div></a>

<?php
}

/**
 * Template fuer die Darstellung von Items des Tages
 * @param Object $item Item des Tages
 */
function itemOfTheDay( $item ) {
	?><div class="rr_box"><div class="rr_box_heading">Item of the day</div><?php HTML_redrugolok::showSmall( $item );?></div>
	<?php
}

/**
 * Fuelle ein Item <var>$item</var> aus und speichere
 * @param Object $item
 *
 */
function fillOut( $item ) {
	global $mainframe, $Itemid, $redrugolokPath, $mosConfig_live_site, $my;
?>
<div id="itembody" class="itembody">
	<?php
	$checkID = md5(microtime());
		?>

			
			
			
			<div style="float:left; width: 60%; padding: 5px">
				<h1><?=_RR_LEGEND_GENERAL;?></h1>
				<div class="fieldname"><?=_RR_TITLE; ?></div> <div class="fieldarea"><input type="text" name="itemTitle" id="itemTitle" value="<?=(isset($_POST["title"]))?$_POST["title"]:'';?>" maxlegth="64"><a title="<?=_RR_TRANSLIT_THIS?>" href="javascript:;" onClick="lat_to_rus(name);"><img src="<?=$mosConfig_live_site?>/images/icons/lat_to_cyr.gif" style="border:0px; height:20px; width:20px; margin-top:2px;" alt="<?=_RR_TRANSLIT_THIS?>" /></a></div>
				<div class="fieldname"><?=_RR_DESCRIPTION; ?></div> <div class="fieldarea"><textarea name="itemDescription" id="itemDescription" cols="40" rows="7" onChange="item.setDescription(this.id, document.getElementById('itemDescription').value)"><?=(isset($_POST["description"]))?$_POST["description"]:'';?></textarea><a title="<?=_RR_TRANSLIT_THIS?>" href="javascript:;" onClick="lat_to_rus(description);"><img src="<?=$mosConfig_live_site?>/images/icons/lat_to_cyr.gif" style="border:0px; height:20px; width:20px; margin-top:2px;" alt="<?=_RR_TRANSLIT_THIS?>" /></a></div>
			
			</div>
			
			
			
  
			
			<div style="float:left; width: 30%; padding: 5px; border-left: 1px solid #E0E0E0">
				<h3><?=_RR_LEGEND_OPTIONS;?></h3>
				<div class="fieldname"><?=_RR_AUTHORS; ?></div>
				<div class="fieldarea"><input type="text" name="addAuthor" id="addAuthor" value=""></div><div class="fieldarea"><a href="javascript:addAuthor();"><img src="<?=$redrugolokPath?>/images/icon_add.png"></a> <a title="<?=_RR_TRANSLIT_THIS?>" href="javascript:;" onClick="lat_to_rus(addAuthor);"><img src="<?=$mosConfig_live_site?>/images/icons/lat_to_cyr.gif" style="border:0px; height:20px; width:20px; margin-top:2px;" alt="<?=_RR_TRANSLIT_THIS?>" /></a></div>
				<div class="fieldarea" style="clear: left"><ul id="authorsarea"></ul></div>
				<div id="clr"></div>
			
				<div class="fieldname"><?=_RR_KEYWORDS; ?></div>
				<div class="fieldarea"><input type="text" name="addKeyword" id="addKeyword" value=""></div><div class="fieldarea"><a href="javascript:addKeyword();"><img src="<?=$redrugolokPath?>/images/icon_add.png"></a> <a title="<?=_RR_TRANSLIT_THIS?>" href="javascript:;" onClick="lat_to_rus(addKeyword);"><img src="<?=$mosConfig_live_site?>/images/icons/lat_to_cyr.gif" style="border:0px; height:20px; width:20px; margin-top:2px;" alt="<?=_RR_TRANSLIT_THIS?>" /></a></div>
				<div class="fieldarea" style="clear: left"><ul id="keywordsarea"></ul></div>
				<div id="clr"></div>
				
				<div class="fieldname"><?=_RR_INSPIREDBY; ?></div>
				<div class="fieldarea"><input type="text" name="inspiredby" id="inspiredby" value="<?=(isset($_POST["inspiredby"]))?$_POST["inspiredby"]:'';?>" maxlegth="256"><a title="<?=_RR_TRANSLIT_THIS?>" href="javascript:;" onClick="lat_to_rus(inspiredby);"><img src="<?=$mosConfig_live_site?>/images/icons/lat_to_cyr.gif" style="border:0px; height:20px; width:20px; margin-top:2px;" alt="<?=_RR_TRANSLIT_THIS?>" /></a></div>
				<div id="clr"></div>
				
				<div class="fieldname"><?=_RR_SHOWME; ?></div>
				<div class="fieldarea"><input type="checkbox" name="showme" id="showme" value="1" <?=(isset($_POST["showme"]) and ($_POST["showme"] == 0))? '' : 'checked';?>></div>
				<div id="clr"></div>
				
				<div class="fieldname"><?=_RR_RATEME; ?></div>
				<div class="fieldarea"><input type="checkbox" name="rateme" id="rateme" value="1" <?=(isset($_POST["rateme"]) and ($_POST["rateme"] == 0))? '' : 'checked';?>></div>
				<div id="clr"></div>
			</div>
			
			<div class="clr"></div>
			
			<div style="float:left; width: 60%; padding: 5px;">
				<h1><?=_RR_LEGEND_CATEGORY;?></h1>
				
				<div><ul id="itemarea"></ul></div>
				<div class="clr"></div>
				
				
				
			</div>
			
			<div style="float:left; width: 30%; padding: 5px; border-left: 1px solid #E0E0E0">
				<h2><?=_RR_LEGEND_ITEMS;?></h2>
				
				<?php 
					$type = null;
					$types = getTypes(); 
					?><div class="fieldname"><?=_RR_TYPE?></div>
					<div class="fieldarea"><select name="selectType" id="selectType" onChange="javascript: selectItemType();"> 
						<option value="-1" selected><?=_RR_TYPE_SELECT?></option>
					<?php
					foreach($types as $type) {
						?><option value="<?=$type->id?>"><?=$type->name?></option><?php
					}
					?></select></div>
					<div id="clr"></div>
					<div id="fieldsarea"></div>
					 
					<?php
				
				?>
			
			</div>


			<script language="JavaScript" type="text/javascript">
				item = new Item();
				item.setTitle( "itemTitle", "<?=(isset($_POST["itemTitle"]))?$_POST["itemTitle"]:'';?>" );
				item.setDescription( "itemDescription", "<?=(isset($_POST["itemDescription"]))?$_POST["itemDescription"]:'';?>" );	
  				item.addAuthor("<?=$my->username?>");
			
				function output() {
					document.getElementById("output").innerHTML = '';
					for (a in item) {
  						document.getElementById("output").innerHTML += a + ": ";
  						document.getElementById("output").innerHTML += item.eval(a) + "<br/>";
					}
				}
				
				function gen() {
					item.generateForm();
					
				}
				
				
			</script>


			<div class="clr"></div>
		<form name="form" id="form" method="post" action="<?php sefRelToAbs("index.php?option=com_redrugolok&Itemid=<?=$Itemid?>&task=add"); ?>">
			<div id="output"></div>
			<input type="hidden" name="submited" id="submited" value="fillOut">
			<input type="hidden" name="checkID" id="checkID" value="<?=$checkID?>">
			<div style="width:90%; clear: both;">
				<input onClick="gen();" type="button" name="submit" id="submit" class="button" value="generate">
				<input type="submit" name="submit" id="submit" class="button" value="<?=_RR_SAVE; ?>">
			</div>
		
			
		</form>
	<?php ?>
</div>
<div class="itemfooter">
</div>
<?php
}

/**
 * Ein Item wurde erfolreich gespeichert
 * @param Zieger auf Objekt &$item Gerade gespeichertes Objekt
 */
function insert_success($item) {
?>
<div id="itemheader" class="itemheader">
	<div class="contentheading">
		<?=_RR_TITLE_INSERT_OK?>
	</div>
</div>
<div id="itembody" class="itembody">
	<?php 
	HTML_item::show(&$item); 
	?>
</div>
<div class="itemfooter">
</div>
<?php

}

/**
 * Bearbeite ein Item <var>$item</var> und speichere
 * @param Object $item
 *
 */
function editItem( $item ) {
?>

<div id="itemheader" class="itemheader">
	<div class="contentheading">
			<?=_RR_EDIT_ITEM?>
	</div>
</div>
<div id="itembody" class="itembody">
	<?php
	HTML_item::htmlUpdate($item); ?>
</div>
<div class="itemfooter">
</div>
<?php
}

/**
 * Ein Item wurde erfolreich gespeichert
 * @param Zieger auf Objekt &$item Gerade gespeichertes Objekt
 */
function update_success($item) {

?>
<div id="itemheader" class="itemheader">
	<div class="contentheading">
			<?=_RR_TITLE_UPDATE_OK?>
	</div>
</div>
<div id="itembody" class="itembody">
	<?php 
	HTML_item::show(&$item); 
	?>
</div>
<div class="itemfooter">
</div>
<?php

}

/**
 * Template zur Ausgabe von einer Meldung fuer nicht authoriesierte Personen
 */
function NotAuth() {
	$introtext = NotAuth();
	?>
	<div style="margin: 10px;border: solid 1px #FF0000"><?=$introtext;?></div>
 	<input type="button" name="name" value="<?=_RR_BACK?>" class="button" onClick="javascript: history.back();"/>


	<?php
}

/**
 * Darstellung einer Warnung oder eines Fehlers
 */
function warning($text = '', $button = 1) {
	echo "<div class=\"warning\">";
	if($text == '')
		echo _RR_WARNING;
	else
		echo $text;

	echo "</div>";

	($button == 1) ? print "<input type=\"button\" value=\""._RR_BACK."\" onClick=\"javascript: history.back();\">" : print "";

}

}

?>
